package cn.mesmile.admin.common.config.swagger;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zb
 * @Description
 *     # 关闭spring自带的映射，会导致swagger也不能访问，需指定swagger的静态资源处理
 *     spring.web.resources.add-mappings: false  会导致swagger也不能访问
 */
@Configuration
public class SwaggerResourceMvcConfig implements WebMvcConfigurer {

    /**
     * 需指定swagger的静态资源处理
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 这里加上任意路径后会去匹配上，/error 资源，返回默认的404页面，所以这里先注释
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

        /** 配置knife4j 显示文档 */
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        /**
         * 配置swagger-ui显示文档
         */
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        /** 公共部分内容 */
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }


}
